<!--

/*
* Copyright (C) 2005-2014 University of Sydney
*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* editRecord.html
* Main Heurist search page: this page is the effective home page for the Heurist application *
*
* @author      Tom Murtagh
* @author      Kim Jackson
* @author      Ian Johnson   <ian.johnson@sydney.edu.au>
* @author      Stephen White   <stephen.white@sydney.edu.au>
* @author      Artem Osmakov   <artem.osmakov@sydney.edu.au>
* @copyright   (C) 2005-2013 University of Sydney
* @link        http://Sydney.edu.au/Heurist
* @version     3.1.0
* @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package     Heurist academic knowledge management system
* @subpackage  !!!subpackagename for file such as Administration, Search, Edit, Application, Library
*/

-->

<html>

    <head>
        <title>Heurist Academic Knowledge Management System - &copy; 2014 University of Sydney</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <link rel=stylesheet href="../../common/css/global.css">
        <link rel=stylesheet href="../../common/css/edit.css">

        <script type="text/javascript" src="../../external/jquery/jquery.js"></script>
        <script type="text/javascript" src="../../common/js/hintDiv.js"></script>

        <!-- for mapviewer roolover -->
        <!-- scripts for dynamic map popup
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
        <script type="text/javascript" src="../../records/edit/digitizer/digitizer.js"></script>
        <script type="text/javascript" src="../../external/timemap.2.0/lib/mxn/mxn.js?(googlev3)"></script>
        <script type="text/javascript" src="../../external/timemap.2.0/lib/markerclusterer.js"></script>
        <script type="text/javascript" src="../../external/timemap.2.0/src/timemap.js"></script>
        <script type="text/javascript" src="../../viewers/map/mapping.js"></script>
        -->

    </head>
    <body>

        <script type="text/javascript" src="../../external/yui/2.8.2r1/build/yahoo/yahoo-min.js"></script>
        <script type="text/javascript" src="../../external/yui/2.8.2r1/build/json/json-min.js"></script>
        <script src="../../common/js/utilsLoad.js"></script>
        <script src="../../common/js/temporalObjectLibrary.js"></script>
        <script src="../../common/php/getMagicNumbers.php"></script>
        <script src="relationshipsObjectLibrary.js"></script>
        <script src="../../common/php/loadUserInfo.php"></script>

        <script src="../../records/edit/digitizer/mapViewer.js"></script>

        <script>
            top.HEURIST.whenLoaded("obj-user", function() {
                if (!top.HEURIST.baseURL) {
                    top.HEURIST.baseURL = location.protocol + "//" + location.hostname + top.HEURIST.basePath;
                }
                if (! top.HEURIST.is_logged_in()) {

                    var lsearch = top.location.search;
                    //extract dbname
                    var dbname = top.HEURIST.getQueryVar("db");
                    if(dbname){
                        dbname = "db="+dbname+"&";
                    }

                    //redirect to login
                    top.location.replace(top.HEURIST.baseURL +
                    "common/connect/login.php?"+dbname+
                    "last_uri=" + escape(top.HEURIST.baseURL + "records/edit/editRecord.html" + lsearch ));
                }
            });
        </script>
        <script src="../../common/php/loadCommonInfo.php"></script>
        <script src="../../common/php/displayPreferences.php"></script>

        <script src="editRecord.js"></script>
        <!-- script src="inputUrlInclude.js"></script -->
        <script>

            var caller_id_element = top.HEURIST.parameters["caller"]? top.HEURIST.parameters["caller"] :
            (window.location.search.match(/caller=(\d+).*$/)? window.location.search.match(/caller=(\d+).*$/)[1] : "");

            var bibID =(top.HEURIST.parameters["recID"]? top.HEURIST.parameters["recID"] :
            (window.location.search.match(/recID=(\d+).*$/)? window.location.search.match(/recID=(\d+).*$/)[1] : ""));
            var dbname = top.HEURIST.getQueryVar("db");
            if (!dbname) {
                dbname = top.HEURIST.database && top.HEURIST.database.name ? top.HEURIST.database.name: "";
            }

            var bugReportURL = top.HEURIST.baseURL + 'export/email/formEmailRecordPopup.html?rectype=bugreport&db='+dbname;

            var queryStr = "",
            recordEvent = "record";
            if (bibID){
                queryStr = "recID=" + bibID;
            }
            if (top.HEURIST.parameters["bkmk_id"]){
                if (queryStr.length > 0) queryStr += "&";
                queryStr += "bkmk_id="+top.HEURIST.parameters["bkmk_id"];
            }
            if ( queryStr) {
                top.HEURIST.loadScript(top.HEURIST.baseURL +"common/php/loadRecordData.php?db="+dbname+"&"+queryStr,true);
            }

            //
            // reresh element after edit resource record in another window
            //
            function updateFromChild( ele_id_toupdate, value){
                //alert(ele_id_toupdate+" ,  "+value);
                var afrm = document.getElementsByTagName("iframe");
                var i=0, cnt = afrm?afrm.length:0;
                for (;i<cnt;i++){
                    var d = afrm[i].contentDocument;
                    var ele = d.getElementById(ele_id_toupdate);
                    if(ele){
                        ele.value = value;
                        break;
                    }
                }
            }

        </script>
        <script>
            top.HEURIST.whenLoaded([recordEvent,"edit-html"], function() {
                var rec = (top && top.HEURIST && top.HEURIST.edit && top.HEURIST.edit.record ? top.HEURIST.edit.record:null);
                var recID =  ((rec?rec.bibID : 0) || (window.HEURIST ? window.HEURIST.parameters["recID"]:0) || (top.HEURIST ? top.HEURIST.parameters["recID"]:0));
                if (! rec) {
                    //					window.location.replace(top.HEURIST.basePath +"common/html/msgInvalidRecID.html"+ (recID ? "?" + recID : ""));
                }
                if (rec.denied) {
                    //					window.location.replace(window.HEURIST.basePath +"common/html/msgAccessDenied.html"+ (recID ? "?" + recID : ""));
                }
                if (rec.replacedBy) {
                    // This record has been deprecated in favour of another ...
                    // Load that page (and make a best effort to stop this one from continuing)
                    //					window.location.replace("?recID=" + rec.replacedBy +"&db="+dbname);
                }
                top.HEURIST.edit.showRecordProperties();
                if (top.HEURIST.parameters["sid"]) {
                    var surl = top.HEURIST.basePath+"records/edit/setResultsNavigation.php?db="+dbname+"&s="+top.HEURIST.parameters["sid"]+"&id="+top.HEURIST.edit.record.bibID;
                    top.HEURIST.util.getJsonData(surl, function(context) {
                        if (!context || context.count<1) return;
                        document.getElementById("search-nav").innerHTML =
                        "<div style=\"padding:10px 0;\">Record "+context.pos+" of "+context.count+" search results</div>" +
                        "<div>" +
                        (context.prev ? "<a class=\"button\" style=\"height:18px !important\" title='It will save changes' onclick='{top.HEURIST.edit.navigate_torecord(\""+top.HEURIST.parameters["sid"]+
                        '",'+context.prev+"); return false;}'><img src=\""+top.HEURIST.baseURL+"/common/images/nav_prev.png\">previous</a>" : "") +
                        (context.next ? "<a class=\"button\" style=\"float:right; height:18px !important\" title='It will save changes' onclick='{top.HEURIST.edit.navigate_torecord(\""+
                        top.HEURIST.parameters["sid"]+'",'+context.next+"); return false;}'>next<img src=\""+top.HEURIST.baseURL+"/common/images/nav_next.png\"></a>" : "") +

                        //(context.prev ? "<a class=\"button\" style=\"height:18px !important\" href=?db="+dbname+"&sid="+top.HEURIST.parameters["sid"]+"&recID="
                        // +context.prev+"><img src=\""+top.HEURIST.baseURL+"/common/images/nav_prev.png\">previous</a>" : "") +
                        //(context.next ? "<a class=\"button\" style=\"float:right; height:18px !important\" href=?db="+dbname+"&sid="+top.HEURIST.parameters["sid"]+
                        // "&recID="+context.next+">next<img src=\""+top.HEURIST.baseURL+"/common/images/nav_next.png\"></a>" : "") +
                        "<div style=\"clear:both\"></div></div>";
                    });
                }

            });
        </script>
        <script src="../../common/php/loadHAPI.php"></script> <!-- TODO: FIXME:  need to just change hapi to load without instances and keys  -->

        <script>
            top.HEURIST.registerEvent(window, "contentloaded", function() {
                document.getElementById("home-link").href = top.HEURIST.basePath + "?db=" +top.HEURIST.database.name;

                //verify terms and record contraints
                setTimeout(function(){
                    var surl = top.HEURIST.basePath+"admin/verification/listFieldTypeDefinitionErrorsCompact.php?db="+dbname+"&rt="+top.HEURIST.edit.record.rectypeID;
                    top.HEURIST.util.getJsonData(surl, function(context) {
                        if( !top.HEURIST.util.isEmptyVar(context) ){
                            var surl = top.HEURIST.basePath+"admin/verification/listFieldTypeDefinitionErrorsCompact.php?db="+dbname+"&data="+ JSON.stringify(context);
                            top.HEURIST.util.popupURL(top, surl, {width:480, height:420});
                        }

                    });
                },1000);


            });

            top.HEURIST.whenLoaded([recordEvent, "edit-js", "edit-html"], top.HEURIST.edit.loadAllModules);
            top.HEURIST.whenLoaded([recordEvent, "edit-js", "HAPI", "edit-html"],createRectypeChanger );
            window.onbeforeunload = top.HEURIST.edit.onbeforeunload;


            function editRecordType(){

                window.open("../../admin/adminMenu.php?db="+
                top.HEURIST.database.name+
                "&mode=rectype&rtID="+
                top.HEURIST.edit.record.rectypeID, "_blank");

                var smsg = "<p>Changes made to the record type will not become active until you reload the edit form (hit page reload in your browser).</p>"+
                "<br/>Please SAVE the record first in order not to lose data";

                var ele = document.getElementById("editRectype-message-text");
                ele.innerHTML = smsg;
                ele = document.getElementById("editRectype-message");

                var w = top.HEURIST.util.popupTinyElement(top, ele,
                { "no-titlebar": false, "no-close": false, width: 330, height: 140 });

            }

            function createRectypeChanger() {
                var rectypeEdit = document.getElementById("rectype-edit");

                //<span class=\"recID\">" + top.HEURIST.rectypes.typedefs[rectypeID].commonFields[cfi.rty_Name] + ": </span>"
                var rectypeName = document.getElementById("rectype-name");
                rectypeName.innerHTML = top.HEURIST.util.getRectypeIconAndName(top.HEURIST.edit.record.rectypeID);//top.HEURIST.edit.record.rectype;

                var rectypeValSelect = document.createElement("select");
                rectypeValSelect.id = "rectype-select";
                rectypeValSelect.onchange = changeRectype;
                rectypeEdit.appendChild(rectypeValSelect);

                // rectypes displayed in Groups by group display order then by display order within group
                // TODO: This should be using common function with other places record types are being displayed
                // viz. adding record types, selecting record types for pointer field constraints etc.
                var index;
                for (index in top.HEURIST.rectypes.groups){
                    if (index == "groupIDToIndex" ||
                    top.HEURIST.rectypes.groups[index].showTypes.length < 1) continue;
                    var grp = document.createElement("optgroup");
                    grp.label = top.HEURIST.rectypes.groups[index].name;
                    rectypeValSelect.appendChild(grp);
                    for (var recTypeIDIndex in top.HEURIST.rectypes.groups[index].showTypes) {
                        var recTypeID = top.HEURIST.rectypes.groups[index].showTypes[recTypeIDIndex];
                        var name = top.HEURIST.rectypes.names[recTypeID];
                        rectypeValSelect.appendChild(new Option(name, recTypeID));
                        if (name == top.HEURIST.edit.record.rectype) {
                            rectypeValSelect.selectedIndex = rectypeValSelect.options.length-1;
                        }
                    }
                }

                if(top.HEURIST.is_admin()){
                    var edt = document.getElementById("admin_editrectype");
                    edt.innerHTML = "<a href='#' onclick='{editRecordType(); return false;}' style='font-size:1.3em;'>Modify record structure<img src='../../common/images/edit-pencil.png'></a>";
                }
                if(top.HEURIST.edit.record && top.HEURIST.edit.record.isTemporary){
                    top.document.title = "Add ["+top.HEURIST.edit.record.rectype + ", "+ top.HEURIST.edit.record.rectypeID + "] "+top.document.title;
                }else{
                    top.document.title = top.HEURIST.edit.record.title + " [" + top.HEURIST.edit.record.rectype + ", "+ top.HEURIST.edit.record.rectypeID +"] ID:"+top.HEURIST.edit.record.recID +
                    ".  "+top.document.title;
                }

            }

            function changeRectype() {
                var rectypeValue = document.getElementById("rectype-select").value;
                if (top.HEURIST.edit.record.rectype != rectypeValue) {
                    top.HEURIST.edit.record.rectypeID = rectypeValue;
                    top.HEURIST.edit.record.rectype = top.HEURIST.rectypes.names[rectypeValue];

                    // update the public info frame to reflect the change of rectype
                    top.HEURIST.edit.showModule("public");
                    top.HEURIST.edit.modules["public"].frame.contentWindow.setRectype(rectypeValue);
                    top.HEURIST.edit.showRecordProperties();
                }
            }


            function openWorkgroupChanger() {
                if (top.HEURIST.edit.record.visibility == "hidden") {
                    document.getElementById("non-wg-hide").checked = true;
                } else if (top.HEURIST.edit.record.visibility == "viewable"){
                    document.getElementById("non-wg-view").checked = true;
                } else if (top.HEURIST.edit.record.visibility == "pending"){
                    document.getElementById("non-wg-pending").checked = true;
                } else {
                    document.getElementById("non-wg-public").checked = true;
                }

                var wgVal = document.getElementById("new-workgroup-value");
                while (wgVal.childNodes.length) {
                    wgVal.removeChild(wgVal.lastChild);
                }
                var recOwnerID = top.HEURIST.edit.record.workgroupID;
                wgVal.options[0] = new Option("Everyone (no restriction)", "0");
                wgVal.options[1] = new Option(top.HEURIST.get_user_name(), top.HEURIST.get_user_id());
                wgVal.selectedIndex = recOwnerID == top.HEURIST.get_user_id() ? 1:0;
                for (var i=0; i < top.HEURIST.user.workgroups.length; ++i) {
                    var wgID = top.HEURIST.user.workgroups[i];
                    var wgName = top.HEURIST.workgroups[wgID].name;
                    wgVal.options[i+2] = new Option(wgName, wgID);

                    if (wgID == recOwnerID){
                        wgVal.selectedIndex = i+2;
                    }
                }


                var wgEditor = document.getElementById("workgroup-editor");
                wgEditor.style.display = "block";

                var linkPos = top.HEURIST.getPosition(document.getElementById("workgroup-edit"));
                top.HEURIST.util.popupElement(window, wgEditor,
                { width: wgEditor.offsetWidth, height: wgEditor.offsetHeight, x: linkPos.x-200, y: linkPos.y+20, "no-titlebar": true, "no-resize": true });
                setTimeout(function() { wgVal.focus(); }, 0);
            }

            function closeWorkgroupChanger(cancel) {
                if (! cancel) {
                    var wgValue = document.getElementById("new-workgroup-value").value;
                    var wgVisValue = document.getElementById("non-wg-hide").checked? "hidden" : (document.getElementById("non-wg-view").checked?"viewable" : (document.getElementById("non-wg-pending").checked?"pending" : "public"));
                    if (top.HEURIST.edit.record.workgroupID != wgValue  ||  top.HEURIST.edit.record.visibility != wgVisValue) {
                        top.HEURIST.edit.record.workgroupID = wgValue;
                        top.HEURIST.edit.record.workgroup = wgValue > 0 ? (wgValue == top.HEURIST.get_user_id() ? top.HEURIST.get_user_name() : top.HEURIST.workgroups[wgValue].name) : "";
                        top.HEURIST.edit.record.visibility = wgVisValue;

                        top.HEURIST.edit.modules["public"].frame.contentWindow.setWorkgroupProperties(wgValue, wgVisValue);

                        top.HEURIST.edit.showRecordProperties();
                    }
                }

                var popupsList = top.HEURIST.util.popups.list;
                top.HEURIST.util.closePopup(popupsList[popupsList.length-1].id);
            }

        </script>

        <a id=home-link>
            <div id=logo title="Click the logo to return to your Favourites"></div>
        </a>
        <div id=version></div>
        <!-- database name -->
        <a id=dbSearch-link>
            <div id=dbname ></div>
        </a>
        <!-- message of the day TODO: FIX OR REMOVE, SEEMS THIS IS NOT DISPLAYED ALTHOUGH IT IS IN PAGE SOURCE-->
        <div id="message"> Heurist 3 : Open Source <a href="../help/index.html?ACL" target="_blank" title="Click for full information"><br><font style="font-size:11px">Credits</font></a> </div>
        <!-- quicklinks -->
        <div id="quicklinks">
            <div id="logged-in" style="height:22px"></div>
            <ul id=quicklink-cell>
                <li><a href="../../help/index.html" onClick="top.HEURIST.util.popupURL(window, href); return false;"><b>About</b></a></li>
                <li><a href="#" onClick="top.HEURIST.util.popupURL(top, bugReportURL,{'close-on-blur': false,'no-resize': false, height: 320,width: 740,callback: function (title, bd, bibID) {if (bibID) {window.close(bibID, title);}} });return false;" title="Click to send a bug report to the Heurist developers"><b>Report bug</b></a></li>
                <li><a id=contact-link href="mailto:info@heuristscholar.org"><b>Contact us</b></a></li>
            </ul>
        </div>
        <script>
            top.HEURIST.whenLoaded(["edit-html", "obj-common"], top.HEURIST.util.setDBName);
            top.HEURIST.whenLoaded(recordEvent, function() {
                var contactLinkSubject = "HEURIST v" + top.HEURIST.VERSION + " user:"+top.HEURIST.get_user_username() + " edit";
                if (top.HEURIST.edit.record && top.HEURIST.edit.record.bibID) contactLinkSubject += " bibID:"+top.HEURIST.edit.record.bibID;
                if (top.HEURIST.edit.record && top.HEURIST.edit.record.bkmkID) contactLinkSubject += " bkmkID:"+top.HEURIST.edit.record.bkmkID;
                top.document.getElementById("contact-link").href += "?subject=" + encodeURIComponent(contactLinkSubject);
            });
        </script>
        <!-- search -->
        <div id=search  class="roundedBoth outline bannerBG">
            <!-- div class="tablecell" id="edit_record_title">EDIT RECORD</div -->

            <div id=rectype-edit class=edit >
                <!-- div style="display:inline-block;padding-right:2px;"><img id=rectype-img src="../../common/images/16x16.gif"></div -->
                <div id="rectype-name" style="display:inline-block;"></div><img src="../../common/images/edit-pencil.png" id="rectype-change"
                    onclick="{document.getElementById('rectype-name').style.display='none';document.getElementById('rectype-select').style.display='inline-block';}">
            </div>
            <div id=record-title>
                <div id=title-val></div>
            </div>
            <div id="workgroup-div" class="edit-mode-depended">
                <div id=workgroup-val-div title="Restrict access by workgroup" style="white-space:nowrap;">
                    <b><span id=workgroup-val></span></b>
                    <div id=workgroup-edit class="edit admin-only" onClick="openWorkgroupChanger();">
                    <img id=wg-edit-img src="../../common/images/edit-pencil.png"></div>
                </div>
                <div id=workgroup-access title="Access for users not in this workgroup"></div>
            </div>
            <div id="close-button" class="save-record-buttons">
                <input type=button name=save-button value="Close" onClick="top.HEURIST.edit.closeEditWindow();">
            </div>
            <div id="save-record-buttons" class="save-record-buttons" style="display: none;">
                <input type=button name=save-button value="Cancel" onClick="top.HEURIST.edit.cancelSave(false);">
                <input type=button name=save-button value="Save" onClick="top.HEURIST.edit.save_record(false);">
                <input type=button name=save-button value="Save / close" title="Save and Close" onClick="top.HEURIST.edit.save_record(true);">
            </div>
        </div>

        <!-- sidebar -->
        <div id="sidebar" class="edit-mode-depended">
            <div class="sidebar-link disabled" style="background-image: url(../../common/images/user_public.gif);" id=public-link
                disabledDescription="No shared information available as this is marked as a private record"><img src="../../common/images/16x16.gif">
                <b>Shared information</b>
                <span id=desc>Standard data fields for the entity</span>
            </div>

            <div class="sidebar-link disabled" style="background-image: url(../../common/images/user_personal.gif);" id=personal-link
                disabledTitle="Click here to add a bookmark for this record"
                disabledDescription="Click here to bookmark this record"><img src="../../common/images/16x16.gif">
                <b>Private information</b>
                <span id=desc>Tags, passwords, ratings, notifications</span>
            </div>

            <div class="sidebar-link disabled" style="background-image: url(../../common/images/user_workgroup.gif);" id=workgroups-link
                disabledDescription="You are not a member of any workgroup"><img src="../../common/images/16x16.gif">
                <b>Workgroup tags</b>
                <span id=desc>For the workgroups you belong to</span>
            </div>

            <div class="sidebar-link disabled" style="background-image: url(../../common/images/logo_wiki.gif);" id=annotation-link
                disabledDescription="Not available"><img src="../../common/images/16x16.gif">
                <b>Text</b>
                <span id=desc>WYSIWYG extended text &amp; discussion</span>
            </div>

            <div class="sidebar-link disabled" style="background-image: url(../../common/images/relationships_icon.gif);" id=relationships-link
                disabledDescription="Not available"><img src="../../common/images/16x16.gif">
                <b>Relationships</b>
                <span id=desc>Links between related records</span>
            </div>

            <div class="sidebar-nav" style="text-align:right;">

            <!-- TODO: Remove. This code is deprecated by new Save, Save-and-close methodology
                <div style="padding: 3px 0;display:none;">
                    <label for=act-stay >stay on page</label>
                    <input type=radio name=act id=act-stay value="stay"
                        title="Saves the record but keeps this form open for further editing"
                        onclick="top.HEURIST.util.setDisplayPreference('action-on-save', value)">
                </div>
                <div style="padding: 3px 0;display:none;" id="close-window-option">
                    <label for=act-close>close window</label>
                    <input type=radio name=act id=act-close value="close"
                        title="Saves the record and closes the tab or window containing this data entry form"
                        onclick="top.HEURIST.util.setDisplayPreference('action-on-save', value)">
                </div>
                -->

                <div id="close-button2"  style="text-align:right;">
                    <input type=button name=save-button value="Close" style="margin-top:46px;" onClick="top.HEURIST.edit.closeEditWindow();">
                </div>
                <div id="save-record-buttons2" style="text-align:right;display:none">
                    <input type=button name="save-button" value="Cancel" onClick="top.HEURIST.edit.cancelSave(false);"><br />
                    <input type=button name="save-button" style="margin-top:3px;" value="Save" onClick="top.HEURIST.edit.save_record(false);"><br />
                    <input type=button name=save-button style="margin-top:3px;" value="Save / close" onClick="top.HEURIST.edit.save_record(true);">
                </div>
            </div>

            <div id="search-nav" class="sidebar-nav"></div>
        </div>
        <!-- end sidebar -->


        <!-- page -->
        <div id=page>
            <!-- banner -->
            <div class="banner">
                <div style="display:inline-block;margin:3px 10px;vertical-align: middle;">
                    <input type=radio name="editmode" id=input-record-edit-simplemode
                            onClick="top.HEURIST.util.setDisplayPreference('record-edit-advancedmode', this.checked? 'false' : 'true');setEditMode();" class=minimal>
                    <label for=input-record-edit-simplemode>Simple Mode</label>
                    <input type=radio name="editmode" id=input-record-edit-advancedmode
                            onClick="top.HEURIST.util.setDisplayPreference('record-edit-advancedmode', this.checked? 'true' : 'false');setEditMode();" class=minimal>
                    <label for=input-record-edit-advancedmode>Advanced Mode</label>
                </div>
                <a id="help-link" href='#' onClick="top.HEURIST.util.helpToggler(this)" style="width:80px;padding-right:0;text-align:center"></a>
                <div class=public-visible style="display:inline-block;margin:3px 10px">
                    <input type=checkbox id=input-visibility onClick="top.HEURIST.util.setDisplayPreference('input-visibility', this.checked? 'all' : 'recommended')" class=minimal>
                    <label for=input-visibility>show optional fields</label>
                </div>
                <div id="admin_editrectype" style="float:right;width:200px;text-align:right;"  class="edit-mode-depended"></div>
            </div>
            <!-- main panel -->
            <div id="page-inner" class="panel-main-div">
                <div id=tab-holder >
                </div>
            </div>
        </div>
        <!-- end page -->


        <script>
            top.HEURIST.whenLoaded("display-preferences", function() {
                var canCloseWindow = false;
                try {
                    // see if we would be able to close this window with JS
                    if (top.opener != top && top.HEURIST_WINDOW_ID) {
                        canCloseWindow = true;
                    }
                    // otherwise, fall through to a different detail action, and hide the close-window option
                } catch (e) {
                    document.getElementById("close-window-option").style.display = "none";
                }

                switch (top.HEURIST.displayPreferences["action-on-save"]) {
                    case "close":
                    if (canCloseWindow) {
                        //ART document.getElementById("act-close").checked = true;
                        break;
                    }
                    default:
                    /*  IJ request 2012-10-08
                    if (top.HEURIST && top.HEURIST.parameters && top.HEURIST.parameters['fromadd']) {
                    document.getElementById("act-close").checked = true;
                    } else {
                    document.getElementById("act-stay").checked = true;
                    }
                    */
                    //ART document.getElementById("act-stay").checked = true;
                }

                var helpLink = top.document.getElementById("help-link");
                top.HEURIST.util.setHelpDiv(helpLink,null);
            });
        </script>


        <!-- footer -->
        <div id=footer>
            <div id="rty_description" class="help"></div>
            <span class="edit-mode-depended">last accessed: <span id=moddate></span>
                <span>cite as: <a href='#' id=cite-as-url contextmenu=enable onClick="return false;"></a></span>
                <script>
                    top.HEURIST.whenLoaded(recordEvent, function() {
                        document.getElementById("moddate").appendChild(document.createTextNode(top.HEURIST.edit.record.moddate));
                        var citeAs = document.getElementById("cite-as-url");
                        citeAs.href = window.location.protocol + "//" + window.location.host+ top.HEURIST.basePath +"resolver.php?db="+ top.HEURIST.database.name +"&recID=" + top.HEURIST.edit.record.bibID;
                        citeAs.appendChild(document.createTextNode(citeAs.href));
                    });
                </script>
            </span>
        </div>
        <!-- end footer -->


        <div style="position: absolute;">
            <div id="workgroup-editor" style="display: none;">
                <div>
                    <h2>Change record access:</h2>
                </div>
                <div class="detailRow"> <!-- pulldown list of potential owner workgroups -->
                    <label for=new-workgroup-value>Record is editable by</label>
                    <select id=new-workgroup-value class=in></select>
                </div>
                <div class="detailRow">
                    <input type=radio name=new-non-workgroup value=hidden id=non-wg-hide>
                    <label for=non-wg-hide>Only members of this group can view the record</label>
                </div>
                <div class="detailRow">
                    <input type=radio name=new-non-workgroup value=viewable id=non-wg-view>
                    <label for=non-wg-view>Any logged-in user can view the record</label>
                </div>
                <div class="detailRow">
                    <input type=radio name=new-non-workgroup value=pending id=non-wg-pending>
                    <label for=non-wg-pending>Flagged for external publication, any logged-in user</label>
                    <div style="margin-left: 20px; font-style: italic;">No effect on existing external views - hml, html etc.</div>
                    <div style="margin-left: 20px; font-style: italic;">Can be auto-set whenever a public record is edited.</div>
                </div>
                <div class="detailRow">
                    <input type=radio name=new-non-workgroup value=public id=non-wg-public>
                    <label for=non-wg-public>Published - written automatically to external views</label>
                    <!-- TODO: this is implementation dependent. Check if this is implemented at deep enough level to make this statement unequivocally
                    <div style="margin-left: 20px; font-style: italic;">except fields marked as restricted.</div> -->
                </div>
                <div class="detailRow" style="text-align:right; padding-top:15px">
                    <input type=button value="Change" style="font-weight: bold;" onClick="closeWorkgroupChanger();">
                    <input type=button value="Cancel" onClick="closeWorkgroupChanger(true);">
                </div>
            </div>
        </div>

        <div id="editRectype-message" style="display:none;">
            <div id="editRectype-message-text" style="text-align:left;width:310px;color:black;font-weight:bold;margin:10px;"></div>
        </div>

        <div id=workgroup-message style="display: none;">
            <div style="padding: 5px;">
                <h2>Workgroup warning</h2>
                <p>The link you followed attempts to add workgroup ownership and/or workgroup tags to the record you are creating.
                    As you are not a member of the workgroup <span id=workgroup-message-wgname style="font-weight: bold;"></span>, the record will be
                created as an open record without the workgroup information.</p>
                <p>In this context, workgroup tags are generally used to publish records to specific lists.
                    The absence of the workgroup tag probably means that your new record will not appear in the corresponding list(s).
                If it needs to appear there, you will need to ask a member of the workgroup to add the tag(s) later.</p>

                <input type="button" value="OK" onClick="top.HEURIST.util.closePopup(workgroupPopupID);">
            </div>
        </div>

        <script>
            var workgroupPopupID;
            function testWorkgroupMessage() {
                top.HEURIST.deregisterEvent(window, "load", testWorkgroupMessage);

                if (top.HEURIST.parameters["wg"] == top.HEURIST.get_user_id() ||
                !(top.HEURIST.parameters["wg"] ||
                top.HEURIST.parameters["wgkwd"])) {
                    return;
                }
                var wg = top.HEURIST.workgroups[parseInt(top.HEURIST.parameters["wg"])];

                document.getElementById("workgroup-message-wgname").appendChild(document.createTextNode(wg? wg.name : ""));

                var w = top.HEURIST.util.popupElement(top, document.getElementById("workgroup-message"), { "no-titlebar": true, width: 400, height: 300 });
                workgroupPopupID = w.id;
            }
            top.HEURIST.registerEvent(window, "load", testWorkgroupMessage);
        </script>


        <div id=notes-container></div>

        <div>

            <div id="popup-saved" class="popup-message" style="display: none">
                <b>Record saved</b>
            </div>
            <div id="popup-nothingchanged" class="popup-message" style="display: none">
                <b>Nothing changed</b>
            </div>

        </div>

        <script src="../disambig/similarRecordsPopup.js"></script>
        <script>
            function popupDisambiguation(matches) {
                _popupDisambiguation(matches, function(choice) {
                    if (choice.value == -1) {
                        top.HEURIST.edit.record.forceSave = true;
                        var editFrame = top.HEURIST.edit.modules.public.frame;
                        editFrame.contentWindow.document.forms[0].heuristSubmit();
                    }
                    else {
                        var modules = top.HEURIST.edit.modules;
                        for (var eachName in modules) {
                            top.HEURIST.edit.unchanged(eachName);
                        }

                        top.location.replace(top.HEURIST.baseURL+"records/edit/editRecord.html?db="+dbname+"&recID="+choice.details.id);
                    }
                });
            }
        </script>

        <script>
            if (!top.HAPI && typeof HAPI == "object"){
                HAPI.importSymbols(this,top);
            }
            top.HEURIST.contentLoaded();
            top.HEURIST.fireEvent(top, "heurist-edit-html-loaded");

            function setEditMode(){
                if(top.HEURIST.util.getDisplayPreference('record-edit-advancedmode')=="true"){
                    $(".edit-mode-depended").css('display','block');
                    $("#rectype-change").css('display','inline-block');
                    $("#page").css('left','200px');
                    $("#page").css('top','140px');
                    $("#input-record-edit-advancedmode").attr('checked',true);
                }else{
                    $(".edit-mode-depended").css('display','none');
                    $("#rectype-change").css('display','none');
                    $("#page").css('left','10px');
                    $("#page").css('top','120px');
                    $("#input-record-edit-simplemode").attr('checked',true);
                }
            }
            $("#input-record-edit-advancedmode").css('vertical-align','top');
            $("#input-record-edit-simplemode").css('vertical-align','top');
            setEditMode();
        </script>

    </body>
</html>